
import { _decorator, Component, Node, Label, Button, Color } from 'cc';
const { ccclass, property } = _decorator;
 
@ccclass('UIBattleEndController')
export class UIBattleEndController extends Component {

    private _LblTitle: Label = null;
    private _BtnPlayAgain: any = null;

    private _FuncBtnOnclicked: Function = null;

    onLoad () {
        
        var nodeBgDialog = this.node.getChildByName("BgDialog");

        this._LblTitle = nodeBgDialog.getChildByName("LblTitle").getComponent(Label);
        this._BtnPlayAgain = nodeBgDialog.getChildByName("BtnPlayAgain").getComponent(Button);
        this._BtnPlayAgain.opt = 1;
    }

    onEnable() {
        this._BtnPlayAgain.node.on("click", this._onClickBtn, this);

    }

    onDisable() {
        this._BtnPlayAgain.node.off("click", this._onClickBtn, this);

    }

    start () {

    }

    setTitle(strTitle: string, color: string) {
        this._LblTitle.string = strTitle;
    }

    setBtnOnclicked (funcBtnOnclicked: Function) {
        this._FuncBtnOnclicked = funcBtnOnclicked;
    }


    private _onClickBtn(sender: any) {
        if (sender.opt == 1) {
            this.node.removeFromParent();

            if (this._FuncBtnOnclicked) {
                this._FuncBtnOnclicked(sender.opt);
            }
        }
    }
    
}